<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Produk extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->m_produk = new M_produk();
        $this->m_produkdet = new M_produk_det();
    }

    function index() {

        $this->produk();
    }

    function produk() {


        $this->load->library('pagination');
        $config['base_url'] = base_url() . 'main/produk/produk';
        $config['total_rows'] = $this->m_produk->where("status = 1")->count();
        $config['per_page'] = 9;
        $config['uri_segment'] = 4;
        $config['full_tag_open'] = '<p class="paging">';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);
        $data['link_pagging'] = $this->pagination->create_links();
        $hal = $this->uri->segment(4, 0);

        $data['search'] = "";

        $data['menu'] = array(
//            $this->load->view('parsing/client/menu_right_search', '', true),
            $this->load->view('parsing/client/menu_right_katagori', '', true),
            $this->load->view('parsing/client/menu_right_db', '', true),
        );

        $data['title'] = "Daftar Produk";
        $data['list_data'] = $this->m_produk->where("status = 1")->order_by("tanggal", "desc")->limit(9, $hal)->get();
        $data['isi'] = 'isi_produk';

        $this->load->view('template_client', $data);
    }

    function produk_det($id = NULL) {
        $data['menu'] = array(
//            $this->load->view('parsing/client/menu_right_search', '', true),
            $this->load->view('parsing/client/menu_right_katagori', '', true),
            $this->load->view('parsing/client/menu_right_db', '', true),
        );

        $data['title'] = "Keterangan Produk";
        $data['list_produk'] = $this->m_produk->where("id = $id")->get();
        $data['list_pruduk_det'] = $this->m_produkdet->where("id_produk = $id and status = 1")->get();
        $data['isi'] = 'isi_produk_det';

        $this->load->view('template_client', $data);
    }

    function per_katagori($id_katagori = NULL, $ke = NULL) {

        $this->load->library('pagination');
        $config['base_url'] = base_url() . 'main/produk/per_katagori/' . $id_katagori . '/';
        $config['total_rows'] = $this->m_produk->where("id_katagori = $id_katagori and status = 1")->count();
        $config['per_page'] = 9;
        $config['uri_segment'] = 5;
        $config['full_tag_open'] = '<p class="paging">';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);
        $data['link_pagging'] = $this->pagination->create_links();
        $hal = $ke;

        $data['search'] = "";


        $data['menu'] = array(
//            $this->load->view('parsing/client/menu_right_search', '', true),
            $this->load->view('parsing/client/menu_right_katagori', '', true),
            $this->load->view('parsing/client/menu_right_db', '', true),
        );

        $data['title'] = "Daftar Produk";

        if ($id_katagori == "")
            $data['list_data'] = $this->m_produk->get();
        else
            $data['list_data'] = $this->m_produk->where("(id_katagori IN (Select id from katagori where parentid = '$id_katagori') OR id_katagori = '$id_katagori') and status = 1")->limit(9, $hal)->get();

        $data['isi'] = 'isi_produk';
        $this->load->view('template_client', $data);
    }

    function search_produk($search = NULL, $ke = NULL) {
        if ($search == NULL)
            $search = mysql_real_escape_string($this->input->post('search'));

        if ($this->input->post('search') == "" && $search == NULL)
            redirect("main/produk");

        $data['search'] = $search;

        $this->load->library('pagination');
        $config['base_url'] = base_url() . 'main/produk/search_produk/' . $search . '/';
        $config['total_rows'] = $this->m_produk->where("(id like '%$search%' or nama_produk like '%$search%' or warna like '%$search%') and status = 1")->count();
        $config['per_page'] = 9;
        $config['uri_segment'] = 5;
        $config['full_tag_open'] = '<p class="paging">';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);
        $data['link_pagging'] = $this->pagination->create_links();
        $hal = $ke;


        $data['menu'] = array(
//            $this->load->view('parsing/client/menu_right_search', '', true),
            $this->load->view('parsing/client/menu_right_katagori', '', true),
            $this->load->view('parsing/client/menu_right_db', '', true),
        );

        $data['title'] = "Daftar Produk";


        $data['list_data'] = $this->m_produk->where("(id like '%$search%' or nama_produk like '%$search%' or warna like '%$search%') and status = 1")->limit(9, $hal)->get();

        $data['isi'] = 'isi_produk';
        $this->load->view('template_client', $data);
    }

    function cari_stok($id = NULL) {
        $dta = $this->m_produkdet->where("id = $id")->get();
        echo $dta->stok;
    }

}

?>
